//
//  ZH_PlayBackTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/18.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_PlayBackTableViewCell.h"
@interface ZH_PlayBackTableViewCell()
@property (nonatomic,weak)UIView *bgView;
@property (nonatomic,weak)UIImageView *images;
@property (nonatomic,weak)UILabel *titleLabel;
@property (nonatomic,weak)UIButton *rightButton;
@end
@implementation ZH_PlayBackTableViewCell

///创建
+(instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_PlayBackTableViewCell";
    ZH_PlayBackTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_PlayBackTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
}
- (void)loadSubviewConstraints{
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(9));
        make.left.equalTo(self.contentView).offset(FITSCALE(11));
        make.right.equalTo(self.contentView).offset(FITSCALE(-11));
        make.height.mas_equalTo(FITSCALE(196));
        make.bottom.equalTo(self.contentView);
    }];
    [self.images mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.bgView);
        make.height.mas_equalTo(FITSCALE(141));
    }];
    [self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.images.mas_bottom).offset(FITSCALE(15));
        make.right.equalTo(self.bgView).offset(FITSCALE(-11));
        make.width.mas_equalTo(FITSCALE(84));
        make.height.mas_equalTo(FITSCALE(24));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.images.mas_bottom).offset(FITSCALE(21));
        make.left.equalTo(self.bgView).offset(FITSCALE(11));
        make.right.equalTo(self.rightButton.mas_left);
    }];
}
- (void)updataUI:(NSDictionary *)data{
    if (data) {
        if (![data[@"image"] isKindOfClass:[NSNull class]]) {
             [self.images sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"image"]]]];
        }
        self.titleLabel.text = [NSString stringWithFormat:@"%@",data[@"course_name"]];
    }
}
#pragma mark - getter,setter
- (UIView *)bgView{
    if (!_bgView) {
        UIView *view = [UIView createViewWithBackgroundColor:kFontColorWhite];
        view.layer.cornerRadius = FITSCALE(3);
        view.layer.borderWidth = FITSCALE(1);
        view.layer.borderColor = [UIColor colorWithHexString:@"#DFDFDF"].CGColor;
        view.layer.masksToBounds = YES;
        view.clipsToBounds = YES;
        [self.contentView addSubview:_bgView = view];
    }
    return _bgView;
}
- (UIImageView *)images{
    if (!_images) {
        UIImageView *image = [UIImageView createImageViewWithName:@"img_banner"];
        image.layer.masksToBounds = YES;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_images = image];
    }
    return _images;
}
- (UIButton *)rightButton{
    if (!_rightButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"进入学习 ▷" target:self action:nil];
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        button.layer.cornerRadius = FITSCALE(10);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        [self.contentView addSubview:_rightButton = button];
    }
    return _rightButton;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        UILabel *label = [UILabel createLabelWithText:@"标题信息..." font:kFontSize_26];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
@end
